<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ page import = "jdbc.*" %>
<%@ page import = "java.util.*" %>
<%@ page import = "java.text.SimpleDateFormat" %>
<%@ page import = "java.util.Date" %>
<!DOCTYPE html>
<html lang="en">
     <head>
     <title>博客</title>
     <meta charset="utf-8">
     <meta name = "format-detection" content = "telephone=no" />
     <link rel="icon" href="images/favicon.ico" type="image/x-icon">
     <link rel="stylesheet" href="css/style.css">
     <link rel="stylesheet" href="css/font-awesome.min.css">
     <link rel="stylesheet" href="css/stuck.css">
     <link rel="stylesheet" href="css/jquery.fancybox-1.3.4.css">
     <link rel="stylesheet" href="css/sForm.css">
     <script src="js/jquery-1.11.1.min.js"></script>
     <script src="js/jquery-migrate-1.2.1.js"></script>
     <script src="js/jquery.easing.1.3.js"></script>
     <script src="js/jquery.ui.totop.js"></script>
     <script src="js/jquery.equalheights.js"></script>
	 <script src="js/script.js"></script>
     <script src="js/superfish.js"></script>
     <script src="js/jquery.mobilemenu.js"></script>
     <script src="js/sForm.js"></script>
     <script src="js/tmStickUp.js"></script>
     <script src="js/jquery.fancybox-1.3.4.js"></script>
     <script src="js/sForm.js"></script>
     <!--[if lt IE 8]>
       <div style=' clear: both; text-align:center; position: relative;'>
         <a href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home?ocid=ie6_countdown_bannercode">
           <img src="http://storage.ie6countdown.com/assets/100/images/banners/warning_bar_0000_us.jpg" border="0" height="42" width="820" alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today." />
         </a>
      </div>
    <![endif]-->
    <!--[if lt IE 9]>
   		<script src="js/html5shiv.js"></script>
    	<link rel="stylesheet" type="text/css" media="screen" href="css/ie.css">
    <![endif]-->
     </head>
     <body>
<!--============================== Header =================================-->
	<%@ include file = "./header.jsp" %>

<!--======= Content ================================-->

<%

JdbcDao mysql = new JdbcDao();
int aid = 0;
if (request.getParameter("aid") != null)
	aid = Integer.parseInt(request.getParameter("aid"));
System.out.println(aid);
        		   
HashMap<String, String> art = mysql.getArticleInfo(aid);
String time = art.get("time");
if (time == null) time = "0000-00-0000000000000000";
String day = time.substring(8,10);
String mmyy = time.substring(5,7) + "月, " + time.substring(0,4);
String tm = time.substring(10);

String author = mysql.getPersonalInfo(art.get("authoremail"), "realname");

List<HashMap<String, String>> coms = mysql.searchArticleByCommentto(aid);

String cktag = request.getParameter("tags");
String search = request.getParameter("s");

List<HashMap<String, String>> newcoms = mysql.searchArticleByTag("comment");

%>


<style>
.grid_3 {
width: initial;
}

.mycontent {
margin-left: 59px;
margin-top: 12px;
}
.mycontent img {
width: initial;
}

.comment .mycontent{
margin-left: 132px;
margin-top: -15px;
margin-bottom: 20px;
}

.comment .post_date_day {
padding-left: 30px;
}
.comment .post_date {
margin-bottom: -7px;
}
.comment .post_date_month {
text-align: right;
}
.omitc {
margin-top: 19px;
overflow: hidden;
height: 366px;
}
.teaser img {
margin-top: 19px;
overflow: hidden;
}
.teaser video {
margin-top: 19px;
overflow: hidden;
}
.teaser {
overflow: hidden;
}
.omitc img {
display: none;
}
.omitc video {
display: none;
}

.lcomm .grid_2 {
width: 100%;
}

.lcomm .a-side_block {
margin-bottom: 34px;
}
<%
if (search != null) {
%>
.grid_8 {
}
.a-side {
display:none;
}
.teaser {
display:none;
}
.grid_4 {
width: 100%;
}
.omitc {
height: 90px;
}
footer {
display:none;
}
<% } %>
</style>
<script type="text/javascript">

$(document).ready(function() {
	var posts = $(".teaser_post");
	for (var i=0; i<posts.length; i++) {
		var post = posts.eq(i);
		var vd = post.find("video");
		var ins = post.find(".insert_here");
		if (vd.length>0) {
			vd = vd.eq(0);
			//alert(vd.attr("src"));
			vd.attr("preload", "auto");
			ins.append(vd);
			continue;
		}
		var img = post.find("img");
		if (img.length>0) {
			img = img.eq(0);
			//alert(img.attr("src"));
			ins.append(img);
		}
	}
})

</script>
<!--======= Blog & A-Side =======-->
<div class="content blog">
    <div class="container">
        <div class="row">
            <div class="grid_8">
            <% 
            if (aid == 0) {
            	if (search == null)
            		out.print("<h3>所有文章</h3>");
            	else
            		out.print("<h3>搜索结果 “" + search + "”</h3>");
            	for (int i=0; i<coms.size(); i++) {
            		art = coms.get(i);
            		aid = Integer.parseInt(art.get("articleid"));
            		time = art.get("time");
            		if (time == null) time = "0000-00-0000000000000000";
            		day = time.substring(8,10);
            		mmyy = time.substring(5,7) + "月, " + time.substring(0,4);
            		tm = time.substring(10);

            		author = mysql.getPersonalInfo(art.get("authoremail"), "realname");
            		
            		if (cktag != null) {
            			 if (art.get("tags") == null)
            				continue;
            			 String tag = art.get("tags");
            			 System.out.println(tag);
            			 System.out.println(cktag);
            			 System.out.println(tag.indexOf(cktag));
            			 if (tag.indexOf(cktag) == -1)
            				continue;
            		}
            		
            		if (search != null) {
            			String title = art.get("title");
            			String content = art.get("content");
            			if (title.indexOf(search) == -1 && content.indexOf(search) == -1)
            				continue;
            		}

            %>
                <div class="post teaser_post">
                    <div class="row">
                        <div class="grid_1 post_date">
                            <time datetime="<%= time %>">
                            <span class="post_date_day"><%= day %></span>
                            <span class="post_date_month"><%= mmyy %></span></time>
                        </div>
                        <div class="grid_7">
                            <h4 class="post_title"><a href="./article.jsp?aid=<%= aid %>"><%= art.get("title") %></a></h4>
                            <div class="row">
                                <div class="grid_3 post_sub-title">
                                    <span><a href="./account.jsp?uemail=<%=art.get("authoremail")%>">By <%= author %></a></span>
                                    <div class="post_sub-title_sep"></div>
                                    <span><a href="#">TAGS <%= art.get("tags") %></a></span>
                                    <div class="post_sub-title_sep"></div>
                                    <span><a href="#">Time <%= tm %></a></span>
                                    <div class="post_sub-title_sep"></div>
                                    <span><a href="./ueditor/index.jsp?raid=<%= aid %>" class="various iframe forbidden_hide invalid_hide">comment</a></span>
                                    <% if (art.get("authoremail").equals(email_status) || ppt.equals("admin")) { %>
                                    <div class="post_sub-title_sep"></div>
                                    <span><a href="./ueditor/index.jsp?aid=<%= aid %>" class="various iframe">Edit</a></span>
                                    <div class="post_sub-title_sep"></div>
                                    <span><a href="./../articleops.jsp?operator=delReply&articleid=<%= aid %>" class="delbut iframe">Delete</a></span>
									<% } %>                                
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="grid_4 post_img teaser">
                            <a href="#" class="insert_here"></a>
                        </div>
                        <div class="grid_4 post_text">
                            
                    	<div class="omitc">
                        <%= art.get("content") %>
                        </div>
                            
                            <a href="./article.jsp?aid=<%= aid %>" class="link">
                                <span class="link_text">Read More</span>
                                <span class="link_arrow">>></span>
                            </a>
                        </div>
                    </div>
                </div>
            <% }} else { %>
            
                <h3>查看文章</h3>
                <div class="post">
                    <div class="row">
                        <div class="grid_1 post_date">
                            <time datetime="<%= time %>">
                            <span class="post_date_day"><%= day %></span>
                            <span class="post_date_month"><%= mmyy %></span></time>
                        </div>
                        <div class="grid_7">
                            <h4 class="post_title"><a href="./article.jsp?aid=<%= aid %>"><%= art.get("title") %></a></h4>
                            <div class="row">
                                <div class="grid_3 post_sub-title">
                                    <span><a href="./account.jsp?uemail=<%=art.get("authoremail")%>">By <%= author %></a></span>
                                    <div class="post_sub-title_sep"></div>
                                    <span><a href="#">TAGS <%= art.get("tags") %></a></span>
                                    <div class="post_sub-title_sep invalid_hide forbidden_hide"></div>
                                    <span><a href="#"><%= coms.size() %> comments</a></span>
                                    <div class="post_sub-title_sep"></div>
                                    <span><a href="#">Time <%= tm %></a></span>
                                    <div class="post_sub-title_sep"></div>
                                    <span><a href="./ueditor/index.jsp?raid=<%= aid %>" class="various iframe">comment</a></span>
                                    <% if (art.get("authoremail").equals(email_status) || ppt.equals("admin")) { %>
                                    <div class="post_sub-title_sep"></div>
                                    <span><a href="./ueditor/index.jsp?aid=<%= aid %>" class="various iframe">Edit</a></span>
                                    <div class="post_sub-title_sep"></div>
                                    <span><a href="./../articleops.jsp?operator=delReply&articleid=<%= aid %>" class="delbut iframe">Delete</a></span>
                                    <% } %>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                    	<div class = "mycontent">
                        <%= art.get("content") %>
                        </div>
                        <!-- 
                        <div class="grid_4 post_img">
                            <a href="#"><img src="images/page-6_img-3.jpg" alt=""></a>
                        </div>
                        <div class="grid_4 post_text">
                            <h4><a href="#">magnis dis parturient montes, nascetur ridiculus mus.</a></h4>
                            <p class="p__indent-1">Lorem ipsum dolor sit amet. Consectetuer adipiscing elit. Sed laoreet aliquam leo. Ut tellus dolor, dapibus eget, elementum vel. Cursus eleifend, elit. Aenean auctor wisi et urna. Aliquam erat volutpat. Duis ac turpis. Integer rutrum ante eu lacus. </p>
                            <p class="p__indent-2">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent vestibulum molestie lacus. Aenean nonummy hendrerit mauris. Phasellus porta. </p>
                            <a href="#" class="link">
                                <span class="link_text">Read More</span>
                                <span class="link_arrow">>></span>
                            </a>
                        </div>
                        -->
                    </div>
                </div>
                <h3>所有评论</h3>
                <%
if (coms != null)
for (int i=0; i<coms.size(); i++) {

HashMap<String, String> c_art = coms.get(i);

int c_aid = Integer.parseInt(c_art.get("articleid"));
        		   
String c_time = c_art.get("time");
if (time == null) time = "0000-00-0000000000000000";
String c_day = time.substring(8,10);
String c_mmyy = time.substring(5,7) + "月, " + time.substring(0,4);
String c_tm = time.substring(10);

String c_author = mysql.getPersonalInfo(c_art.get("authoremail"), "realname");
                %>
                <div class="post__last comment">
                    <div class="row">
                        <div class="grid_1 post_date">
                            <time datetime="<%= c_time %>">
                            <span class="post_date_day"><i class="fa fa-reply"></i></span>
                            <span class="post_date_month">#<%= i %></span></time>
                            
                        </div>
                        <div class="grid_7">
                            <h4><a href="./article.jsp?aid=<%= c_aid %>"><%= c_art.get("title") %></a></h4>
                            <div class="row">
                                <div class="grid_3 post_sub-title">
                                    <span><a href="./account.jsp?uemail=<%=c_art.get("authoremail")%>">By <%= c_author %></a></span>
                                    <div class="post_sub-title_sep"></div>
                                    <span><a href="#"><%= c_day + "日"+ c_mmyy %></a></span>
                                    <% if (c_art.get("authoremail").equals(email_status) || ppt.equals("admin")) { %>
                                    <div class="post_sub-title_sep"></div>
                                    <span><a href="./ueditor/index.jsp?aid=<%= c_aid %>" class="various iframe">Edit</a></span>
                                    <div class="post_sub-title_sep"></div>
                                    <span><a href="./../articleops.jsp?operator=delReply&articleid=<%= c_aid %>" class="delbut iframe">Delete</a></span>
									<% } %>                                
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                    	<div class = "mycontent">
                        <%= c_art.get("content") %>
                        </div>
                    </div>
                </div>
                
                <% } }%>
            </div>
            <div class="grid_4 a-side lcomm">
                <div class="">
                    <h3>分类</h3>
                    <ul class="list totag">
                        <li><a href="#">公告活动</a></li>
                        <li><a href="#">信息汇总</a></li>
                        <li><a href="#">视频资源</a></li>
                        <li><a href="#">教务公告</a></li>
                        <li><a href="#">学术活动</a></li>
                        <li><a href="#">论文答辩预告</a></li>
                        <li><a href="#">科研通知</a></li>
                        <li><a href="#">首页新闻</a></li>
                        <li><a href="#">海 报</a></li>
                    </ul>                    
                </div>
                <h3>最新评论</h3>
                <%
                
                for (int i=0; i<newcoms.size(); i++) {
                	if (i > 10) break;
                	String title = newcoms.get(i).get("title");
                	String content= newcoms.get(i).get("content");
                	String id = newcoms.get(i).get("articleid");
                
                %>
                <div class="a-side_block">
                    <div class="row">
                        <div class="grid_2">
                            <h4><a href="./article.jsp?aid=<%=id%>"><%=title%></a></h4>
                            <p><%=content%></p>
                        </div>
                    </div>
                </div>
                <% } %>
            </div>
        </div>
    </div>
</div>


<!--======= Footer =================================-->

<!--======= To Top Button =================================-->

<%@ include file = "./footer.jsp" %>

</body>
</html>